/*
* 鼠标移入头像，显示用户信息
* */
function show() {
    $(".profile-img").attr("class", "profile-img active");
    $(".user-panel").show();
}

/**
 * 鼠标移出头像，隐藏用户信息
 */
function hide() {
    $(".profile-img").attr("class", "profile-img");
    $(".user-panel").hide();
}

/**
 * 注销登录
 */
function LoginOut() {
    $.ajax({
        url: `${API}/auth/logout`,
        type: "post",
        dataType: "json",
        xhrFields: {withCredentials: true},
        success: function (result) {
            alert("退出登录成功！");
            window.location = `${Url}` + "/%E4%BC%9A%E5%91%98%E8%B4%AD.html";
        }
    });
}

/**
 * 渲染商品详情
 * @param obj
 */
function detail(obj) {
    window.location= `${Url}` + "/detail.html?id=" + $(obj).attr("id");
}

/**
 * 添加想去次数
 */
function wantGo() {
    $.ajax({
        type: 'PUT',
        url: `${API}/item/WantGo`,
        data: {id:GetQueryString('id')},
        success: function(){
            var count = $("#wantGo").text();
            count = count.substr(0, count.lastIndexOf("人想去"));
            count = parseInt(count) + 1;
            $("#wantGo").text(count+ "人想去");
        }
    });
}

/**
 * 获取地址栏参数
 * @param name
 * @returns {string|null}
 * @constructor
 */
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

/**
 * 跳转订单页面
 * @param id
 * @returns {null}
 */
function readyOrder(id) {
    window.open(`${Url}` + "/ready.html?id=" + id + "&count=" + $('.count-number').text());
    return null;
}

/**
 * 添加订单数量
 */
function addOrderCount() {
    const $count = $('.count-number');
    $count.text(Number($count.text()) + 1);
}

/**
 * 减少订单数量
 */
function cutOrderCount() {
    const $count = $('.count-number');
    const number = Number($count.text());
    //不能小于1
    if (number > 1) {
        $count.text(number - 1);
    }
}